var msg = {
    countMsg: "不能为空！",
    realminMsg: "请输入正浮点数！",
    name: "您输入内容包含特殊符号！",
    phone: "手机格式不正确！",
    chinese: "只能输入中文字符！",
    numb:"只能输入正整数",
    email:"邮箱格式不正确"

}


var focusVerify = function(inputId){
    var inputIdMsg = "#"+inputId+"Msg";
    var inputId = "#"+inputId;
    $(inputIdMsg).html("");
    // $(inputId).val("");
}

var verify = function (str, inputId, type) {
    var inputIdMsg = "#"+inputId+"Msg";
    var inputId = "#"+inputId;
    if (str == ""){
        return;
    }
    if (type == 'realmin') {
        if (!realminVerify(str)) {
            $(inputIdMsg).html(msg.realminMsg);
            // $(inputId).val("");
            return;
        }
    }
    if (type == 'userName'){
        if (!chineseVerify(str)){
            $(inputIdMsg).html(msg.chinese);
            $(inputId).val("");
            return;
        }else{
        	$(inputIdMsg).html("");
        }
    }
    if (type == 'phone'){
        if (!phoneVarify(str)){
            layer.msg("提示："+msg.phone);
            $(inputIdMsg).html(msg.phone);
            // $(inputId).val("");
            return;
        }
    }
    if (type == 'chinese'){
        if (!chineseVerify(str)){
            $(inputIdMsg).html(msg.chinese);
            return;
        }
    }
    if (type == 'shopName'){
        if (!chineseVerify(str)){
            $(inputIdMsg).html(msg.chinese);
             $(inputId).val("");
            return;
        }
    }
    if (type == 'salesMan'){
        if (!chineseVerify(str)){
            $(inputIdMsg).html(msg.chinese);
             $(inputId).val("");
            return;
        }
    }


}

var submitVerify = function (queryModel) {
    var verifyBo = true;
    if(queryModel.shopName == ""){
    	$("#shopNameMsg").html(msg.countMsg);
    	verifyBo = false;
    }else if(queryModel.userName == ""){
   	 $("#userNameMsg").html(msg.countMsg);
     verifyBo = false;
	}else if(!chineseVerify(queryModel.userName)){
		$("#userNameMsg").html(msg.chinese);
		 verifyBo = false;
	}else if (queryModel.mobile == ""){
        $("#mobileMsg").html(msg.countMsg);
        verifyBo = false;
    }else if(!phoneVarify(queryModel.mobile)) {
    	$("#mobileMsg").html(msg.phone);
    	verifyBo = false;
    }else if(queryModel.address == ""){
    	 $("#addressMsg").html(msg.countMsg);
         verifyBo = false;
    }else if(queryModel.email == ""){
    	$("#emailMsg").html(msg.countMsg);
        verifyBo = false;
    }else if(!emailVerify(queryModel.email)){
    	$("#emailMsg").html(msg.email);
        verifyBo = false; 
    }else if(queryModel.deliverCycle == ""){
    	$("#deliverCycleMsg").html(msg.countMsg);
        verifyBo = false;
    }else if(!integerVerify(queryModel.deliverCycle)){
    	$("#deliverCycleMsg").html(msg.numb);
        verifyBo = false; 
    }else if(queryModel.bankOfDeposit == ""){
    	$("#bankOfDepositMsg").html(msg.countMsg);
        verifyBo = false;
    }else if(!integerVerify(queryModel.bankOfDeposit)){
    	$("#bankOfDepositMsg").html(msg.numb);
        verifyBo = false;  
    }else if(queryModel.account == ""){
    	$("#accountMsg").html(msg.countMsg);
        verifyBo = false;
    }else if(!integerVerify(queryModel.account)){
    	$("#accountMsg").html(msg.numb);
        verifyBo = false;   
    }else if(queryModel.businessLicenseNo == ""){
    	$("#businessLicenseNoMsg").html(msg.countMsg);
        verifyBo = false;
    }else if(!integerVerify(queryModel.businessLicenseNo)){
    	$("#businessLicenseNoMsg").html(msg.numb);
        verifyBo = false;    
    }else if(queryModel.shopType == ""){
    	$("#remarkMsg").html(msg.countMsg);
        verifyBo = false;  
    }else if(queryModel.taxRegistrationNo == ""){
    	$("#taxRegistrationNoMsg").html(msg.countMsg);
        verifyBo = false; 
    }else if(!integerVerify(queryModel.taxRegistrationNo)){
    	$("#taxRegistrationNoMsg").html(msg.numb);
        verifyBo = false;    
    }else if(queryModel.orgCode == ""){
    	$("#orgCodeMsg").html(msg.countMsg);
        verifyBo = false; 
    }
    return verifyBo;
}

//中文验证
var chineseVerify = function (str) {
    var pattern = /[\u4e00-\u9fa5]/;
    return(pattern.test(str));
}

//手机号码验证
var phoneVarify = function (str) {
    var pattern = /0?(13|14|15|18)[0-9]{9}/;
    return(pattern.test(str));
}

//正浮点数
var realminVerify = function (str) {
    var pattern = /[1-9]\d*.\d*|0.\d*[1-9]\d*/;
    // console.log(pattern.test(str));
    return pattern.test(str);
}

//名称验证
var userNameVerify = function (str) {
    var pattern = /[A-Za-z0-9_\-\u4e00-\u9fa5]+/;
    // console.log(pattern.test(str));
    return pattern.test(str);
}

//正整数验证
var integerVerify = function (str) {
    // console.log(str)
    var pattern = /^[1-9]\d*$/;
    // console.log(pattern.test(str));
    return pattern.test(str);
}

var certNoVerify = function (str) {
    var pattern = /\d{17}[\d|x]|\d{15}/;
    return pattern.test(str);
}

//时间格式验证
var dateVerify = function (str) {
    var pattern = /\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}/;
    return pattern.test(str);
}
//邮箱验证  
var emailVerify = function (str) {
    var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
    return pattern.test(str);
}

// layui.use(['form', 'layedit', 'laydate'], function(){
//     var form = layui.form()
//         ,layer = layui.layer
//         ,layedit = layui.layedit
//         ,laydate = layui.laydate;
//
//     //自定义验证规则
//     form.verify({
//         title: function(value){
//             if(value.length < 5){
//                 return '标题至少得5个字符啊';
//             }
//         }, fname: function(value){
//             if(value.length < 4){
//                 return '请输入至少4位的用户名';
//             }
//         }, contact: function(value){
//             if(value.length < 4){
//                 return '内容请输入至少4个字符';
//             }
//         }
//         ,supplierName: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
//         ,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
//     });
//
//     //创建一个编辑器
//     layedit.build('LAY_demo_editor');
//
//     //监听提交
//     form.on('submit(demo1)', function(data){
//         layer.alert(JSON.stringify(data.field), {
//             title: '最终的提交信息'
//         })
//         return false;
//     });
//
//
// });
